package recycle.controller;

import recycle.pojo.Inrepository;
import recycle.service.InrepositoryService;
import recycle.utils.Page;
import recycle.vo.InrepositoryParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：入库表 控制器
* @author 孙冉
* @date 2019/07/22
*/
@RestController
@RequestMapping("/inrepository")
public class InrepositoryController{
	@Resource
	private InrepositoryService inrepositoryService;
 	
 	@RequestMapping("/findById.json")
    public Inrepository findById(Integer inRepositoryId){
        Inrepository result = null;
        try {
            result = inrepositoryService.findById(inRepositoryId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Inrepository对象
     */
    @RequestMapping("/findAll.json")
    public List<Inrepository> findAll(){
        List<Inrepository> result = null;
        try {
            result = inrepositoryService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Inrepository对象
     */
    @RequestMapping("/save.json")
    public Map save(Inrepository inrepository){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存入库表失败");
        try {
            if(inrepositoryService.save(inrepository)>0){
                result.put("flag",true);
                result.put("msg","保存入库表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除入库表对象
     * @param inRepositoryId
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer inRepositoryId){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存入库表失败");
        try {
            if(inrepositoryService.delete(inRepositoryId)>0){
                result.put("flag",true);
                result.put("msg","保存入库表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新入库表对象
     */
    @RequestMapping("/update.json")
    public Map update(Inrepository inrepository){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新入库表失败");
        try {
            if( inrepositoryService.update(inrepository)>0){
                result.put("flag",true);
                result.put("msg","更新入库表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Inrepository> query(InrepositoryParam param){
        List<Inrepository> result = null;
        try {
            result = inrepositoryService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(InrepositoryParam param){
        Page result = null;
        try {
            result = inrepositoryService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
 }
